package com.muyu.system.controller;


import com.muyu.common.core.domain.Result;
import com.muyu.common.core.utils.poi.ExcelUtil;
import com.muyu.common.core.web.controller.BaseController;
import com.muyu.common.core.web.page.TableDataInfo;
import com.muyu.common.log.annotation.Log;
import com.muyu.common.log.enums.BusinessType;
import com.muyu.system.domain.DanmoProductFootprint;
import com.muyu.system.dto.FootDTO;
import com.muyu.system.dto.ShoppingCountDTO;
import com.muyu.system.service.IDanmoProductFootprintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * 商品足迹Controller
 * 
 * @author yangle
 * @date 2025-03-12
 */
@RestController
@RequestMapping("/productFootprint")
public class DanmoProductFootprintController extends BaseController
{
    @Autowired
    private IDanmoProductFootprintService danmoProductFootprintService;

    /**
     * 查询商品足迹列表
     */
//    @RequiresPermissions("system:productFootprint:list")
    @GetMapping("/list")
    public Result<TableDataInfo<DanmoProductFootprint>> list(DanmoProductFootprint danmoProductFootprint)
    {
        startPage();
        List<DanmoProductFootprint> list = danmoProductFootprintService.selectDanmoProductFootprintList(danmoProductFootprint);
        return getDataTable(list);
    }

    /**
     * 导出商品足迹列表
     */
//    @RequiresPermissions("system:productFootprint:export")
    @Log(title = "商品足迹", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DanmoProductFootprint danmoProductFootprint)
    {
        List<DanmoProductFootprint> list = danmoProductFootprintService.selectDanmoProductFootprintList(danmoProductFootprint);
        ExcelUtil<DanmoProductFootprint> util = new ExcelUtil<DanmoProductFootprint>(DanmoProductFootprint.class);
        util.exportExcel(response, list, "商品足迹数据");
    }

    /**
     * 获取商品足迹详细信息
     */
//    @RequiresPermissions("system:productFootprint:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(danmoProductFootprintService.selectDanmoProductFootprintById(id));
    }

    /**
     * 新增商品足迹
     */
//    @RequiresPermissions("system:productFootprint:add")
    @Log(title = "商品足迹", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public Result add(@RequestBody DanmoProductFootprint danmoProductFootprint)
    {
        return danmoProductFootprintService.insertDanmoProductFootprint(danmoProductFootprint);
    }

    /**
     * 修改商品足迹
     */
//    @RequiresPermissions("system:productFootprint:edit")
    @Log(title = "商品足迹", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DanmoProductFootprint danmoProductFootprint)
    {
        return danmoProductFootprintService.updateDanmoProductFootprint(danmoProductFootprint);
    }

    /**
     * 删除商品足迹
     */
//    @RequiresPermissions("system:productFootprint:remove")
    @Log(title = "商品足迹", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return danmoProductFootprintService.deleteDanmoProductFootprintByIds(ids);
    }
    /**
     * 商品足迹
     */
    @PostMapping("/footprint")
    public List<Map<String, Object>> footprint(@RequestBody DanmoProductFootprint danmoProductFootprint)
    {
           return danmoProductFootprintService.footprint(danmoProductFootprint);
    }

    /**
     * 店铺足迹
     */
    @PostMapping("/flagship")
    public List<Map<String, Object>> flagship(@RequestBody DanmoProductFootprint danmoProductFootprint)
    {
        return danmoProductFootprintService.flagship(danmoProductFootprint);
    }

    /**
     * 查询昨天今日足迹以及粉丝数量
     */
    @PostMapping("/count")
    public Result<FootDTO> count(@RequestBody ShoppingCountDTO shoppingCountDTO)
    {
        return danmoProductFootprintService.count(shoppingCountDTO);
    }
}
